var app = getApp();
var submitapi = require('../../api/note.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: 0,
    moduledata: {},
    notedata: [],
    textarealength: 0,
    score: 3,
    textdata: "",
    type: "index",
    btnactive: 2,
    slider: true,
    textstatus: true,
    shownotemenu:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData(
      { id: options.id }
    )
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (this.data.id) {
      //首页登入
      if (this.data.id == "index") {
        this.setData(
          { slider: false }
        )
        this.setData(
          { score: 0 }
        )
        this.setData(
          { btnactive: 1 }
        )
      } else {
        //非首页登入
        this.setData(
          { textstatus: false }
        )
        this.setData(
          { shownotemenu: true }
        )
      }
    } else {
      that.showToast('获取分类失败。', 'none');
    }
    submitapi.getallnote(this);
  },

  changetextstate: function () {
    this.setData(
      { textstatus: !this.data.textstatus }
    )
  },

  //发表留言块
  sliderchange: function (e) {
    this.setData({
      score: e.detail.value
    })
  },
  textareachange: function (e) {
    this.setData({
      textarealength: e.detail.cursor
    })
    this.setData({
      textdata: e.detail.value
    })
  },
  showToast: function (title, icon) {
    wx.showToast({
      title: title,
      icon: icon,
      duration: 3000
    })
  },
  submit: function (uinfo) {
    var that = this;
    wx.getSetting({
      success(res) {
        if (res.authSetting['scope.userInfo']) {
          submitapi.submitNoteApi(that, uinfo);
        } else {
          that.showToast('评论功能需要获取头像和昵称。', 'none');
          wx.openSetting({
            success(res) {
             
              // res.authSetting = {
              //   "scope.userInfo": true
              // }
            }
          })
        }
      }
    })
  },
  showjubao: function () {
    wx.showModal({
      title: '举报方法',
      content: '如果需要举报某条含有违法违规或涉及敏感信息等不适合的内容，请复制右下角灰色的id发到群里',
      showCancel: false,
    })
  },
  getallnote: function () {
    submitapi.getallnote(this);
    this.setData(
      { btnactive: 1 }
    )
    this.setData(
      { textstatus: true }
    ),
    this.setData(
      { slider: false }
    )

  },
  getunitnote: function () {
    submitapi.getunitnote(this);
    this.setData(
      { btnactive: 2 }
    ),
    this.setData(
      { textstatus: false }
    ),
    this.setData(
      { slider: true }
    )
  }
})